package com.ruoyi.web.controller.reward;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.reward.domain.OfferReward;
import com.ruoyi.reward.service.IOfferRewardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * rewardController
 *
 * @author YuYang
 * @date 2021-11-11
 */
@RestController
@RequestMapping("/reward/reward")
public class OfferRewardController extends BaseController
{
    @Autowired
    private IOfferRewardService offerRewardService;

    /**
     * 查询reward列表
     */
    @PreAuthorize("@ss.hasPermi('reward:reward:list')")
    @GetMapping("/list")
    public TableDataInfo list(OfferReward offerReward)
    {
        startPage();
        List<OfferReward> list = offerRewardService.selectOfferRewardList(offerReward);
        return getDataTable(list);
    }

    /**
     * 导出reward列表
     */
    @PreAuthorize("@ss.hasPermi('reward:reward:export')")
    @Log(title = "reward", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OfferReward offerReward)
    {
        List<OfferReward> list = offerRewardService.selectOfferRewardList(offerReward);
        ExcelUtil<OfferReward> util = new ExcelUtil<OfferReward>(OfferReward.class);
        return util.exportExcel(list, "reward数据");
    }

    /**
     * 获取reward详细信息
     */
    @PreAuthorize("@ss.hasPermi('reward:reward:query')")
    @GetMapping(value = "/{rewardId}")
    public AjaxResult getInfo(@PathVariable("rewardId") Long rewardId)
    {
        return AjaxResult.success(offerRewardService.selectOfferRewardByRewardId(rewardId));
    }

    /**
     * 新增reward
     */
    @PreAuthorize("@ss.hasPermi('reward:reward:add')")
    @Log(title = "reward", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OfferReward offerReward)
    {
        return toAjax(offerRewardService.insertOfferReward(offerReward));
    }

    /**
     * 修改reward
     */
    @PreAuthorize("@ss.hasPermi('reward:reward:edit')")
    @Log(title = "reward", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OfferReward offerReward)
    {
        return toAjax(offerRewardService.updateOfferReward(offerReward));
    }

    /**
     * 删除reward
     */
    @PreAuthorize("@ss.hasPermi('reward:reward:remove')")
    @Log(title = "reward", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rewardIds}")
    public AjaxResult remove(@PathVariable Long[] rewardIds)
    {
        return toAjax(offerRewardService.deleteOfferRewardByRewardIds(rewardIds));
    }
}
